<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>登录 | 美多商城</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../C02-Users/FindPassword/index.html" />
    
    
    <link rel="prev" href="../C02-Users/DRF-JWT.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="2.6"
        data-chapter-title="登录"
        data-filepath="C02-Users/Login.md"
        data-basepath=".."
        data-revision="Thu May 24 2018 15:58:46 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        美多商城
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="C01-Prepare/index.html">
            
                
                    <a href="../C01-Prepare/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        项目准备
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="C01-Prepare/BusinessModel.html">
            
                
                    <a href="../C01-Prepare/BusinessModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        商业模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="C01-Prepare/DevelopmentProcess.html">
            
                
                    <a href="../C01-Prepare/DevelopmentProcess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        开发流程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="C01-Prepare/ProductAnalysis.html">
            
                
                    <a href="../C01-Prepare/ProductAnalysis.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        需求分析
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="C01-Prepare/ProjectStructure.html">
            
                
                    <a href="../C01-Prepare/ProjectStructure.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        项目架构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="C01-Prepare/StartProject.html">
            
                
                    <a href="../C01-Prepare/StartProject.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        创建工程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="C01-Prepare/Config.html">
            
                
                    <a href="../C01-Prepare/Config.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        配置
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="C02-Users/index.html">
            
                
                    <a href="../C02-Users/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        用户部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="C02-Users/UserModel.html">
            
                
                    <a href="../C02-Users/UserModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        用户模型类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="C02-Users/Register.html">
            
                
                    <a href="../C02-Users/Register.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="C02-Users/CORS.html">
            
                
                    <a href="../C02-Users/CORS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        跨域CORS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="C02-Users/JWT.html">
            
                
                    <a href="../C02-Users/JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        JWT
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="C02-Users/DRF-JWT.html">
            
                
                    <a href="../C02-Users/DRF-JWT.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        Django REST framework JWT
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="2.6" data-path="C02-Users/Login.html">
            
                
                    <a href="../C02-Users/Login.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        登录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="C02-Users/FindPassword/index.html">
            
                
                    <a href="../C02-Users/FindPassword/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        找回密码
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="C02-Users/FindPassword/Step1.html">
            
                
                    <a href="../C02-Users/FindPassword/Step1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.1.</b>
                        
                        第一步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="C02-Users/FindPassword/Step2.html">
            
                
                    <a href="../C02-Users/FindPassword/Step2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.2.</b>
                        
                        第二步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.3" data-path="C02-Users/FindPassword/Step3.html">
            
                
                    <a href="../C02-Users/FindPassword/Step3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.3.</b>
                        
                        第三步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7.4" data-path="C02-Users/FindPassword/Step4.html">
            
                
                    <a href="../C02-Users/FindPassword/Step4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.4.</b>
                        
                        第四步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="C02-Users/QQLogin/index.html">
            
                
                    <a href="../C02-Users/QQLogin/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        QQ登录
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.8.1" data-path="C02-Users/QQLogin/Step1.html">
            
                
                    <a href="../C02-Users/QQLogin/Step1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.1.</b>
                        
                        第一步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8.2" data-path="C02-Users/QQLogin/Step2.html">
            
                
                    <a href="../C02-Users/QQLogin/Step2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.2.</b>
                        
                        第二步
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8.3" data-path="C02-Users/QQLogin/Step3.html">
            
                
                    <a href="../C02-Users/QQLogin/Step3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.3.</b>
                        
                        第三步
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="C02-Users/UserInfo.html">
            
                
                    <a href="../C02-Users/UserInfo.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.9.</b>
                        
                        用户中心个人信息
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="C02-Users/Email/index.html">
            
                
                    <a href="../C02-Users/Email/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.</b>
                        
                        邮件与验证
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.10.1" data-path="C02-Users/Email/DjangoEmail.html">
            
                
                    <a href="../C02-Users/Email/DjangoEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.1.</b>
                        
                        Django发送邮件的方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10.2" data-path="C02-Users/Email/SendEmail.html">
            
                
                    <a href="../C02-Users/Email/SendEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.2.</b>
                        
                        保存邮箱并发送验证邮件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.10.3" data-path="C02-Users/Email/VerifyEmail.html">
            
                
                    <a href="../C02-Users/Email/VerifyEmail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.10.3.</b>
                        
                        验证邮箱链接
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="C02-Users/Address/index.html">
            
                
                    <a href="../C02-Users/Address/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.</b>
                        
                        收货地址
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.11.1" data-path="C02-Users/Address/AreaSelect.html">
            
                
                    <a href="../C02-Users/Address/AreaSelect.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.1.</b>
                        
                        省市区地址查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11.2" data-path="C02-Users/Address/Cache.html">
            
                
                    <a href="../C02-Users/Address/Cache.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.2.</b>
                        
                        使用缓存
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.11.3" data-path="C02-Users/Address/UserAddressManagement.html">
            
                
                    <a href="../C02-Users/Address/UserAddressManagement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.11.3.</b>
                        
                        用户地址管理
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="C03-Goods/index.html">
            
                
                    <a href="../C03-Goods/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        商品部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="C03-Goods/DatabaseDesign.html">
            
                
                    <a href="../C03-Goods/DatabaseDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        数据表设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="C03-Goods/FastDFS.html">
            
                
                    <a href="../C03-Goods/FastDFS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        FastDFS分布式文件系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="C03-Goods/Docker/index.html">
            
                
                    <a href="../C03-Goods/Docker/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Docker使用
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="C03-Goods/Docker/Introduce.html">
            
                
                    <a href="../C03-Goods/Docker/Introduce.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                        Docker简介
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="C03-Goods/Docker/InstallAndOperations.html">
            
                
                    <a href="../C03-Goods/Docker/InstallAndOperations.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.2.</b>
                        
                        安装与操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="C03-Goods/FastDFSDocker.html">
            
                
                    <a href="../C03-Goods/FastDFSDocker.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        使用Docker安装FastDFS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="C03-Goods/FastDFSClientAndDjangoFileSystem.html">
            
                
                    <a href="../C03-Goods/FastDFSClientAndDjangoFileSystem.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        FastDFS客户端与自定义文件存储系统
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="C03-Goods/CKEditor.html">
            
                
                    <a href="../C03-Goods/CKEditor.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        CKEditor富文本编辑器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="C03-Goods/ImportGoodsData.html">
            
                
                    <a href="../C03-Goods/ImportGoodsData.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        添加测试数据
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="C03-Goods/FreezeHTML.html">
            
                
                    <a href="../C03-Goods/FreezeHTML.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        页面静态化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.9" data-path="C03-Goods/DjangoCrontab.html">
            
                
                    <a href="../C03-Goods/DjangoCrontab.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        定时任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="C03-Goods/GenerateIndexHTMLScript.html">
            
                
                    <a href="../C03-Goods/GenerateIndexHTMLScript.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        静态化首页的手动脚本
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.11" data-path="C03-Goods/GoodsDetail.html">
            
                
                    <a href="../C03-Goods/GoodsDetail.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.11.</b>
                        
                        商品详情页面
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.12" data-path="C03-Goods/HotSaleGoods.html">
            
                
                    <a href="../C03-Goods/HotSaleGoods.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.12.</b>
                        
                        热销商品
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.13" data-path="C03-Goods/UserBrowseHistory.html">
            
                
                    <a href="../C03-Goods/UserBrowseHistory.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.13.</b>
                        
                        用户浏览历史记录
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.14" data-path="C03-Goods/GoodsList.html">
            
                
                    <a href="../C03-Goods/GoodsList.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.14.</b>
                        
                        商品列表页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.15" data-path="C03-Goods/GoodsSearch.html">
            
                
                    <a href="../C03-Goods/GoodsSearch.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.15.</b>
                        
                        商品搜索
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="C04-Cart/index.html">
            
                
                    <a href="../C04-Cart/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        购物车部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="C04-Cart/DataStructureDesign.html">
            
                
                    <a href="../C04-Cart/DataStructureDesign.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        购物车数据存储设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="C04-Cart/Implement.html">
            
                
                    <a href="../C04-Cart/Implement.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        购物车实现
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="C04-Cart/MergeCart.html">
            
                
                    <a href="../C04-Cart/MergeCart.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        登录合并购物车
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="C05-Order/index.html">
            
                
                    <a href="../C05-Order/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        订单部分
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="C05-Order/OrderDBModel.html">
            
                
                    <a href="../C05-Order/OrderDBModel.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        订单数据库设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="C05-Order/PlaceOrder.html">
            
                
                    <a href="../C05-Order/PlaceOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        订单结算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="C05-Order/SaveOrder.html">
            
                
                    <a href="../C05-Order/SaveOrder.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        保存订单
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="C05-Order/OrderSuccess.html">
            
                
                    <a href="../C05-Order/OrderSuccess.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        下单成功
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="C06-Pay/index.html">
            
                
                    <a href="../C06-Pay/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        支付宝支付
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="C06-Pay/Alipay.html">
            
                
                    <a href="../C06-Pay/Alipay.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        接入支付宝
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="C06-Pay/Paying.html">
            
                
                    <a href="../C06-Pay/Paying.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        发起支付
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="C06-Pay/PaymentResult.html">
            
                
                    <a href="../C06-Pay/PaymentResult.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        保存支付结果
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="C07-Xadmin.html">
            
                
                    <a href="../C07-Xadmin.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        Xadmin
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8" data-path="C08-Permission.html">
            
                
                    <a href="../C08-Permission.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.</b>
                        
                        用户权限控制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9" data-path="C09-Database/index.html">
            
                
                    <a href="../C09-Database/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.</b>
                        
                        数据库读写分离
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="C09-Database/MasterSlave.html">
            
                
                    <a href="../C09-Database/MasterSlave.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        主从同步配置
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="9.2" data-path="C09-Database/ReadWriteSeparate.html">
            
                
                    <a href="../C09-Database/ReadWriteSeparate.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.2.</b>
                        
                        Django数据库读写分离
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="C10-Deploy.html">
            
                
                    <a href="../C10-Deploy.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        Django部署
                    </a>
            
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >美多商城</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x767B;&#x5F55;">&#x767B;&#x5F55;</h1>
<h4 id="&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;">&#x540E;&#x7AEF;&#x63A5;&#x53E3;&#x8BBE;&#x8BA1;&#xFF1A;</h4>
<p>&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#xFF1A; POST   /authorizations/</p>
<p>&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;&#x540D;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>username</td>
<td>str</td>
<td>&#x7528;&#x6237;&#x540D;</td>
</tr>
<tr>
<td>password</td>
<td>str</td>
<td>&#x5BC6;&#x7801;</td>
</tr>
</tbody>
</table>
<p>&#x8FD4;&#x56DE;&#x6570;&#x636E;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x8FD4;&#x56DE;&#x503C;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x8BF4;&#x660E;</th>
</tr>
</thead>
<tbody>
<tr>
<td>username</td>
<td>str</td>
<td>&#x7528;&#x6237;&#x540D;</td>
</tr>
<tr>
<td>user_id</td>
<td>int</td>
<td>&#x7528;&#x6237;id</td>
</tr>
<tr>
<td>token</td>
<td>str</td>
<td>&#x8EAB;&#x4EFD;&#x8BA4;&#x8BC1;&#x51ED;&#x636E;</td>
</tr>
</tbody>
</table>
<p>Django REST framework JWT&#x63D0;&#x4F9B;&#x4E86;&#x767B;&#x5F55;&#x83B7;&#x53D6;token&#x7684;&#x89C6;&#x56FE;&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> rest_framework_jwt.views <span class="hljs-keyword">import</span> obtain_jwt_token

urlpatterns = [
    url(<span class="hljs-string">r&apos;authorizations/&apos;</span>, obtain_jwt_token, name=<span class="hljs-string">&apos;authorizations&apos;</span>),
]
</code></pre>
<p>&#x4F46;&#x662F;&#x9ED8;&#x8BA4;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x4EC5;&#x6709;token&#xFF0C;&#x6211;&#x4EEC;&#x8FD8;&#x9700;&#x5728;&#x8FD4;&#x56DE;&#x503C;&#x4E2D;&#x589E;&#x52A0;username&#x548C;user_id&#x3002;</p>
<p>&#x901A;&#x8FC7;&#x4FEE;&#x6539;&#x8BE5;&#x89C6;&#x56FE;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x53EF;&#x4EE5;&#x5B8C;&#x6210;&#x6211;&#x4EEC;&#x7684;&#x9700;&#x6C42;&#x3002;</p>
<p>&#x5728;users/utils.py &#x4E2D;&#xFF0C;&#x521B;&#x5EFA;</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">jwt_response_payload_handler</span><span class="hljs-params">(token, user=None, request=None)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x81EA;&#x5B9A;&#x4E49;jwt&#x8BA4;&#x8BC1;&#x6210;&#x529F;&#x8FD4;&#x56DE;&#x6570;&#x636E;
    &quot;&quot;&quot;</span>
    <span class="hljs-keyword">return</span> {
        <span class="hljs-string">&apos;token&apos;</span>: token,
        <span class="hljs-string">&apos;user_id&apos;</span>: user.id,
        <span class="hljs-string">&apos;username&apos;</span>: user.username
    }
</code></pre>
<p>&#x4FEE;&#x6539;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</p>
<pre><code class="lang-python"><span class="hljs-comment"># JWT</span>
JWT_AUTH = {
    <span class="hljs-string">&apos;JWT_EXPIRATION_DELTA&apos;</span>: datetime.timedelta(days=<span class="hljs-number">1</span>),
    <span class="hljs-string">&apos;JWT_RESPONSE_PAYLOAD_HANDLER&apos;</span>: <span class="hljs-string">&apos;users.utils.jwt_response_payload_handler&apos;</span>,
}
</code></pre>
<h3 id="&#x589E;&#x52A0;&#x652F;&#x6301;&#x7528;&#x6237;&#x540D;&#x4E0E;&#x624B;&#x673A;&#x53F7;&#x5747;&#x53EF;&#x4F5C;&#x4E3A;&#x767B;&#x5F55;&#x8D26;&#x53F7;">&#x589E;&#x52A0;&#x652F;&#x6301;&#x7528;&#x6237;&#x540D;&#x4E0E;&#x624B;&#x673A;&#x53F7;&#x5747;&#x53EF;&#x4F5C;&#x4E3A;&#x767B;&#x5F55;&#x8D26;&#x53F7;</h3>
<p>JWT&#x6269;&#x5C55;&#x7684;&#x767B;&#x5F55;&#x89C6;&#x56FE;&#xFF0C;&#x5728;&#x6536;&#x5230;&#x7528;&#x6237;&#x540D;&#x4E0E;&#x5BC6;&#x7801;&#x65F6;&#xFF0C;&#x4E5F;&#x662F;&#x8C03;&#x7528;Django&#x7684;&#x8BA4;&#x8BC1;&#x7CFB;&#x7EDF;&#x4E2D;&#x63D0;&#x4F9B;&#x7684;authenticate()&#x6765;&#x68C0;&#x67E5;&#x7528;&#x6237;&#x540D;&#x4E0E;&#x5BC6;&#x7801;&#x662F;&#x5426;&#x6B63;&#x786E;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4FEE;&#x6539;Django&#x8BA4;&#x8BC1;&#x7CFB;&#x7EDF;&#x7684;&#x8BA4;&#x8BC1;&#x540E;&#x7AEF;&#xFF08;&#x4E3B;&#x8981;&#x662F;authenticate&#x65B9;&#x6CD5;&#xFF09;&#x6765;&#x652F;&#x6301;&#x767B;&#x5F55;&#x8D26;&#x53F7;&#x65E2;&#x53EF;&#x4EE5;&#x662F;&#x7528;&#x6237;&#x540D;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x624B;&#x673A;&#x53F7;&#x3002;</p>
<p><strong>&#x4FEE;&#x6539;Django&#x8BA4;&#x8BC1;&#x7CFB;&#x7EDF;&#x7684;&#x8BA4;&#x8BC1;&#x540E;&#x7AEF;&#x9700;&#x8981;&#x7EE7;&#x627F;<code>django.contrib.auth.backends.ModelBackend</code>&#xFF0C;&#x5E76;&#x91CD;&#x5199;authenticate&#x65B9;&#x6CD5;&#x3002;</strong></p>
<p><code>authenticate(self, request, username=None, password=None, **kwargs)</code>&#x65B9;&#x6CD5;&#x7684;&#x53C2;&#x6570;&#x8BF4;&#x660E;&#xFF1A;</p>
<ul>
<li>request  &#x672C;&#x6B21;&#x8BA4;&#x8BC1;&#x7684;&#x8BF7;&#x6C42;&#x72EC;&#x4EAB;</li>
<li>username  &#x672C;&#x6B21;&#x8BA4;&#x8BC1;&#x63D0;&#x4F9B;&#x7684;&#x7528;&#x6237;&#x8D26;&#x53F7;</li>
<li>password  &#x672C;&#x6B21;&#x8BA4;&#x8BC1;&#x63D0;&#x4F9B;&#x7684;&#x5BC6;&#x7801;</li>
</ul>
<p><strong>&#x6211;&#x4EEC;&#x60F3;&#x8981;&#x8BA9;&#x7528;&#x6237;&#x65E2;&#x53EF;&#x4EE5;&#x4EE5;&#x7528;&#x6237;&#x540D;&#x767B;&#x5F55;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x4EE5;&#x624B;&#x673A;&#x53F7;&#x767B;&#x5F55;&#xFF0C;&#x90A3;&#x4E48;&#x5BF9;&#x4E8E;authenticate&#x65B9;&#x6CD5;&#x800C;&#x8A00;&#xFF0C;username&#x53C2;&#x6570;&#x5373;&#x8868;&#x793A;&#x7528;&#x6237;&#x540D;&#x6216;&#x8005;&#x624B;&#x673A;&#x53F7;&#x3002;</strong></p>
<p>&#x91CD;&#x5199;authenticate&#x65B9;&#x6CD5;&#x7684;&#x601D;&#x8DEF;&#xFF1A;</p>
<ol>
<li><p>&#x6839;&#x636E;username&#x53C2;&#x6570;&#x67E5;&#x627E;&#x7528;&#x6237;User&#x5BF9;&#x8C61;&#xFF0C;username&#x53C2;&#x6570;&#x53EF;&#x80FD;&#x662F;&#x7528;&#x6237;&#x540D;&#xFF0C;&#x4E5F;&#x53EF;&#x80FD;&#x662F;&#x624B;&#x673A;&#x53F7;</p>
<p>&#x82E5;&#x67E5;&#x627E;&#x5230;User&#x5BF9;&#x8C61;&#xFF0C;&#x8C03;&#x7528;User&#x5BF9;&#x8C61;&#x7684;check_password&#x65B9;&#x6CD5;&#x68C0;&#x67E5;&#x5BC6;&#x7801;&#x662F;&#x5426;&#x6B63;&#x786E;</p>
</li>
</ol>
<p>&#x5728;users/utils.py&#x4E2D;&#x7F16;&#x5199;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get_user_by_account</span><span class="hljs-params">(account)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x6839;&#x636E;&#x5E10;&#x53F7;&#x83B7;&#x53D6;user&#x5BF9;&#x8C61;
    :param account: &#x8D26;&#x53F7;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#x7528;&#x6237;&#x540D;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x624B;&#x673A;&#x53F7;
    :return: User&#x5BF9;&#x8C61; &#x6216;&#x8005; None
    &quot;&quot;&quot;</span>
    <span class="hljs-keyword">try</span>:
        <span class="hljs-keyword">if</span> re.match(<span class="hljs-string">&apos;^1[345789]\d{9}$&apos;</span>, account):
            <span class="hljs-comment"># &#x5E10;&#x53F7;&#x4E3A;&#x624B;&#x673A;&#x53F7;</span>
            user = User.objects.get(mobile=account)
        <span class="hljs-keyword">else</span>:
            <span class="hljs-comment"># &#x5E10;&#x53F7;&#x4E3A;&#x7528;&#x6237;&#x540D;</span>
            user = User.objects.get(username=account)
    <span class="hljs-keyword">except</span> User.DoesNotExist:
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">None</span>
    <span class="hljs-keyword">else</span>:
        <span class="hljs-keyword">return</span> user


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UsernameMobileAuthBackend</span><span class="hljs-params">(ModelBackend)</span>:</span>
    <span class="hljs-string">&quot;&quot;&quot;
    &#x81EA;&#x5B9A;&#x4E49;&#x7528;&#x6237;&#x540D;&#x6216;&#x624B;&#x673A;&#x53F7;&#x8BA4;&#x8BC1;
    &quot;&quot;&quot;</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">authenticate</span><span class="hljs-params">(self, request, username=None, password=None, **kwargs)</span>:</span>
        user = get_user_by_account(username)
        <span class="hljs-keyword">if</span> user <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-keyword">None</span> <span class="hljs-keyword">and</span> user.check_password(password):
            <span class="hljs-keyword">return</span> user
</code></pre>
<p>&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x544A;&#x77E5;Django&#x4F7F;&#x7528;&#x6211;&#x4EEC;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x8BA4;&#x8BC1;&#x540E;&#x7AEF;</p>
<pre><code class="lang-python">AUTHENTICATION_BACKENDS = [
    <span class="hljs-string">&apos;users.utils.UsernameMobileAuthBackend&apos;</span>,
]
</code></pre>
<h3 id="&#x524D;&#x7AEF;&#x4EE3;&#x7801;">&#x524D;&#x7AEF;&#x4EE3;&#x7801;</h3>
<p>&#x5728;login.html&#x4E2D;&#x6DFB;&#x52A0;js&#x5F15;&#x7528;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text/javascript&quot;</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">&quot;/js/vue-2.5.16.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text/javascript&quot;</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">&quot;/js/axios-0.18.0.min.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text/javascript&quot;</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">&quot;/js/host.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-title">script</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text/javascript&quot;</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">&quot;/js/login.js&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>
</code></pre>
<p>&#x589E;&#x52A0;vue&#x8BC6;&#x522B;&#x7684;id</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;login_form_bg&quot;</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">&apos;app&apos;</span>&gt;</span>
</code></pre>
<p>&#x4FEE;&#x6539;&#x8868;&#x5355;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-title">form</span> <span class="hljs-attribute">id</span>=<span class="hljs-value">&quot;login-form&quot;</span> @<span class="hljs-attribute">submit.prevent</span>=<span class="hljs-value">&quot;on_submit&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;text&quot;</span> <span class="hljs-attribute">v-model</span>=<span class="hljs-value">&quot;username&quot;</span> @<span class="hljs-attribute">blur</span>=<span class="hljs-value">&quot;check_username&quot;</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">&quot;&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;name_input&quot;</span> <span class="hljs-attribute">placeholder</span>=<span class="hljs-value">&quot;&#x8BF7;&#x8F93;&#x5165;&#x7528;&#x6237;&#x540D;&#x6216;&#x624B;&#x673A;&#x53F7;&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">v-show</span>=<span class="hljs-value">&quot;error_username&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;user_error&quot;</span> <span class="hljs-attribute">v-cloak</span>&gt;</span>&#x8BF7;&#x586B;&#x5199;&#x7528;&#x6237;&#x540D;&#x6216;&#x624B;&#x673A;&#x53F7;<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;password&quot;</span> <span class="hljs-attribute">v-model</span>=<span class="hljs-value">&quot;password&quot;</span> @<span class="hljs-attribute">blur</span>=<span class="hljs-value">&quot;check_pwd&quot;</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">&quot;pwd&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;pass_input&quot;</span> <span class="hljs-attribute">placeholder</span>=<span class="hljs-value">&quot;&#x8BF7;&#x8F93;&#x5165;&#x5BC6;&#x7801;&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">v-show</span>=<span class="hljs-value">&quot;error_pwd&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;pwd_error&quot;</span> <span class="hljs-attribute">v-cloak</span>&gt;</span>{{ error_pwd_message }}<span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">div</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;more_input clearfix&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;checkbox&quot;</span> <span class="hljs-attribute">v-model</span>=<span class="hljs-value">&quot;remember&quot;</span>&gt;</span> 
        <span class="hljs-tag">&lt;<span class="hljs-title">label</span>&gt;</span>&#x8BB0;&#x4F4F;&#x767B;&#x5F55;<span class="hljs-tag">&lt;/<span class="hljs-title">label</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-title">a</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">&quot;/find_password.html&quot;</span>&gt;</span>&#x5FD8;&#x8BB0;&#x5BC6;&#x7801;<span class="hljs-tag">&lt;/<span class="hljs-title">a</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-title">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">input</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">&quot;submit&quot;</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">&quot;&quot;</span> <span class="hljs-attribute">value</span>=<span class="hljs-value">&quot;&#x767B; &#x5F55;&quot;</span> <span class="hljs-attribute">class</span>=<span class="hljs-value">&quot;input_submit&quot;</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">form</span>&gt;</span>
</code></pre>
<p>&#x5728;js&#x76EE;&#x5F55;&#x4E2D;&#x65B0;&#x5EFA;login.js</p>
<pre><code class="lang-js"><span class="hljs-keyword">var</span> vm = <span class="hljs-keyword">new</span> Vue({
    el: <span class="hljs-string">&apos;#app&apos;</span>,
    data: {
        host: host,
        error_username: <span class="hljs-literal">false</span>,
        error_pwd: <span class="hljs-literal">false</span>,
        error_pwd_message: <span class="hljs-string">&apos;&#x8BF7;&#x586B;&#x5199;&#x5BC6;&#x7801;&apos;</span>,
        username: <span class="hljs-string">&apos;&apos;</span>,
        password: <span class="hljs-string">&apos;&apos;</span>,
        remember: <span class="hljs-literal">false</span>
    },
    methods: {
        <span class="hljs-comment">// &#x83B7;&#x53D6;url&#x8DEF;&#x5F84;&#x53C2;&#x6570;</span>
        get_query_string: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">name</span>)</span>{
            <span class="hljs-keyword">var</span> reg = <span class="hljs-keyword">new</span> <span class="hljs-built_in">RegExp</span>(<span class="hljs-string">&apos;(^|&amp;)&apos;</span> + name + <span class="hljs-string">&apos;=([^&amp;]*)(&amp;|$)&apos;</span>, <span class="hljs-string">&apos;i&apos;</span>);
            <span class="hljs-keyword">var</span> r = <span class="hljs-built_in">window</span>.location.search.substr(<span class="hljs-number">1</span>).match(reg);
            <span class="hljs-keyword">if</span> (r != <span class="hljs-literal">null</span>) {
                <span class="hljs-keyword">return</span> <span class="hljs-built_in">decodeURI</span>(r[<span class="hljs-number">2</span>]);
            }
            <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;
        },
        <span class="hljs-comment">// &#x68C0;&#x67E5;&#x6570;&#x636E;</span>
        check_username: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-keyword">if</span> (!<span class="hljs-keyword">this</span>.username) {
                <span class="hljs-keyword">this</span>.error_username = <span class="hljs-literal">true</span>;
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">this</span>.error_username = <span class="hljs-literal">false</span>;
            }
        },
        check_pwd: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-keyword">if</span> (!<span class="hljs-keyword">this</span>.password) {
                <span class="hljs-keyword">this</span>.error_pwd_message = <span class="hljs-string">&apos;&#x8BF7;&#x586B;&#x5199;&#x5BC6;&#x7801;&apos;</span>;
                <span class="hljs-keyword">this</span>.error_pwd = <span class="hljs-literal">true</span>;
            } <span class="hljs-keyword">else</span> {
                <span class="hljs-keyword">this</span>.error_pwd = <span class="hljs-literal">false</span>;
            }
        },
        <span class="hljs-comment">// &#x8868;&#x5355;&#x63D0;&#x4EA4;</span>
        on_submit: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
            <span class="hljs-keyword">this</span>.check_username();
            <span class="hljs-keyword">this</span>.check_pwd();

            <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.error_username == <span class="hljs-literal">false</span> &amp;&amp; <span class="hljs-keyword">this</span>.error_pwd == <span class="hljs-literal">false</span>) {
                axios.post(<span class="hljs-keyword">this</span>.host+<span class="hljs-string">&apos;/authorizations/&apos;</span>, {
                        username: <span class="hljs-keyword">this</span>.username,
                        password: <span class="hljs-keyword">this</span>.password
                    }, {
                        responseType: <span class="hljs-string">&apos;json&apos;</span>,
                    })
                    .then(response =&gt; {
                        <span class="hljs-comment">// &#x4F7F;&#x7528;&#x6D4F;&#x89C8;&#x5668;&#x672C;&#x5730;&#x5B58;&#x50A8;&#x4FDD;&#x5B58;token</span>
                        <span class="hljs-keyword">if</span> (<span class="hljs-keyword">this</span>.remember) {
                            <span class="hljs-comment">// &#x8BB0;&#x4F4F;&#x767B;&#x5F55;</span>
                            sessionStorage.clear();
                            localStorage.token = response.data.token;
                            localStorage.user_id = response.data.user_id;
                            localStorage.username = response.data.username;
                        } <span class="hljs-keyword">else</span> {
                            <span class="hljs-comment">// &#x672A;&#x8BB0;&#x4F4F;&#x767B;&#x5F55;</span>
                            localStorage.clear();
                            sessionStorage.token = response.data.token;
                            sessionStorage.user_id = response.data.user_id;
                            sessionStorage.username = response.data.username;
                        }

                        <span class="hljs-comment">// &#x8DF3;&#x8F6C;&#x9875;&#x9762;</span>
                        <span class="hljs-keyword">var</span> return_url = <span class="hljs-keyword">this</span>.get_query_string(<span class="hljs-string">&apos;next&apos;</span>);
                        <span class="hljs-keyword">if</span> (!return_url) {
                            return_url = <span class="hljs-string">&apos;/index.html&apos;</span>;
                        }
                        location.href = return_url;
                    })
                    .catch(error =&gt; {
                        <span class="hljs-keyword">this</span>.error_pwd_message = <span class="hljs-string">&apos;&#x7528;&#x6237;&#x540D;&#x6216;&#x5BC6;&#x7801;&#x9519;&#x8BEF;&apos;</span>;
                        <span class="hljs-keyword">this</span>.error_pwd = <span class="hljs-literal">true</span>;
                    })
            }
        },
    }
});
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../C02-Users/DRF-JWT.html" class="navigation navigation-prev " aria-label="Previous page: Django REST framework JWT"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../C02-Users/FindPassword/index.html" class="navigation navigation-next " aria-label="Next page: 找回密码"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
